package com.lrkj.web.phone;


import com.lrkj.common.core.controller.BaseController;
import com.lrkj.common.core.domain.AjaxResult;
import com.lrkj.common.core.page.TableDataInfo;
import com.lrkj.framework.security.MiniContextUtils;
import com.lrkj.phone.domain.AppUser;
import com.lrkj.phone.service.IAppUserService;
import com.lrkj.property.domain.*;
import com.lrkj.property.service.*;
import com.lrkj.property.vo.RoomAuthVo;
import com.lrkj.waitress.domain.RoomCustom;
import com.lrkj.waitress.service.IRoomCustomService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

@RestController
@Api(tags = "手机端资产信息")
public class PropertyController extends BaseController {

    @Autowired
    private ICommunityService communityService;

    @Autowired
    private IRoomService roomService;

    @Autowired
    private IVehicleService vehicleService;

    @Autowired
    private IFloorService floorService;

    @Autowired
    private IUnitService unitService;

    @Autowired
    private IAppUserService appUserService;

    @Autowired
    private IRoomCustomService roomCustomService;

    @Autowired
    private IRoomAuthService roomAuthService;

    /**
     * 查询小区信息列表
     */
    @ApiOperation(value = "查询小区信息列表", notes = "查询小区信息列表")
    @GetMapping("/phone/community/list")
    public TableDataInfo communitylist(Community community) {
        startPage();
        List<Community> list = communityService.selectCommunityList(community);
        return getDataTable(list);
    }

    /**
     * 查询楼栋信息列表
     */
    @ApiOperation(value = "查询楼栋信息列表", notes = "查询楼栋信息列表")
    @GetMapping("/phone/floor/list")
    public TableDataInfo floorlist(Floor floor) {
        startPage();
        List<Floor> list = floorService.selectFloorList(floor);
        return getDataTable(list);
    }


    /**
     * 查询单元信息列表
     */
    @ApiOperation(value = "查询单元信息列表", notes = "查询单元信息列表")
    @GetMapping("/phone/unit/list")
    public TableDataInfo unitlist(Unit unit) {
        startPage();
        List<Unit> list = unitService.selectUnitList(unit);
        return getDataTable(list);
    }

    /**
     * 获取小区车场信息
     */
    @ApiOperation(value = "获取小区车场信息", notes = "获取小区车场信息")
    @GetMapping(value = "/phone/community/getCommunityParking/{id}")
    public AjaxResult getCommunityParking(@PathVariable("id") String id) {
        return AjaxResult.success(communityService.getCommunityParking(id));
    }


    /**
     * 获取小区场地信息
     */
    @ApiOperation(value = "获取小区场地信息", notes = "获取小区场地信息")
    @GetMapping(value = "/phone/community/getCommunitySite/{id}")
    public AjaxResult getCommunitySite(@PathVariable("id") String id) {
        return AjaxResult.success(communityService.getCommunitySite(id));
    }

    /**
     * 获取小区广告位信息
     */
    @ApiOperation(value = "获取小区广告位信息", notes = "获取小区广告位信息")
    @GetMapping(value = "/phone/community/getCommunityAdvert/{id}")
    public AjaxResult getCommunityAdvert(@PathVariable("id") String id) {
        return AjaxResult.success(communityService.getCommunityAdvert(id));
    }


    /**
     * 查询房屋管理列表
     */
    @ApiOperation(value = "查询房屋管理列表", notes = "查询房屋管理列表")
    @GetMapping("/phone/room/list")
    public TableDataInfo roomlist(Room room) {
        startPage();
        List<Room> list = roomService.selectRoomList(room);
        return getDataTable(list);
    }


    /**
     * 查询车辆管理列表
     */
    @ApiOperation(value = "查询车辆管理列表", notes = "查询车辆管理列表")
    @GetMapping("/phone/vehicle/list")
    public TableDataInfo vehiclelist(Vehicle vehicle) {
        startPage();
        List<Vehicle> list = vehicleService.selectVehicleList(vehicle);
        return getDataTable(list);
    }

    /**
     * 我的房产列表
     */
    @ApiOperation(value = "我的房产列表", notes = "我的房产列表")
    @GetMapping("/phone/room/myRoomList")
    public AjaxResult myRoomList() {
        List<RoomCustom> roomCustoms = new ArrayList<>();
        //当前APP用户的手机号码
        String phoneNum = MiniContextUtils.getPhoneNum();
        //通过手机号查询除所有的APP用户id
        List<AppUser> appUsers = appUserService.selectAppUserList(new AppUser("", Long.valueOf(phoneNum)));
        if (null != appUsers && appUsers.size() > 0) {
            List<String> appUserIds = new ArrayList<>();
            appUsers.stream().forEach(x -> {
                appUserIds.add(x.getAppUserId());
            });
            RoomCustom eg = new RoomCustom();
            eg.getParams().put("appUserIdIN", appUserIds);
            eg.setWrVerify("Y");//是否认证
            roomCustoms = roomCustomService.selectRoomCustomList(eg);
        }
        return AjaxResult.success(roomCustoms);
    }

    /**
     * APP用户房间认证
     */
    @ApiOperation(value = "APP用户房间认证", notes = "APP用户房间认证")
    @PostMapping("/phone/room/auth")
    public AjaxResult appUserRoomAuth(@RequestBody RoomAuthVo roomAuth) {
        return AjaxResult.success(roomCustomService.appUserRoomAuth(roomAuth));
    }

    /**
     * 设置用户默认小区房间
     */
    @ApiOperation(value = "设置用户默认小区房间", notes = "设置用户默认小区房间")
    @PostMapping("/phone/room/roomDefault")
    public AjaxResult roomDefault(@RequestBody RoomCustom roomCustom) {
        return toAjax(roomCustomService.roomDefault(roomCustom));
    }


    /**
     * 设置用户默认小区房间
     */
    @ApiOperation(value = "删除APP用户房间绑定关系", notes = "删除APP用户房间绑定关系")
    @PostMapping("/phone/room/delRoomBind")
    public AjaxResult delRoomBind(@RequestBody RoomCustom roomCustom) {
        return toAjax(roomCustomService.delRoomBind(roomCustom));
    }


    @ApiOperation(value = "家庭成员审批列表", notes = "家庭成员审批列表")
    @GetMapping("/phone/room/roomAuthList")
    public TableDataInfo roomAuthList(RoomAuth roomAuth) {
        startPage();
        return getDataTable(roomAuthService.selectRoomAuthList(roomAuth));
    }

    @ApiOperation(value = "家庭成员审批", notes = "家庭成员审批")
    @PostMapping("/phone/room/roomAuthApprove")
    public AjaxResult roomAuthApprove(@RequestBody RoomAuth roomAuth) {
        return toAjax(roomAuthService.roomAuthApprove(roomAuth));
    }

    /**
     * 业主成员列表
     */
    @ApiOperation(value = "业主成员列表", notes = "业主成员列表")
    @GetMapping(value = "/phone/room/roomCustomList")
    public AjaxResult roomCustomList(RoomCustom roomCustom) {
        this.changeParameter(roomCustom.getParams());
        return AjaxResult.success(roomCustomService.selectRoomCustomList(roomCustom));
    }

}
